<template>
  <div class=" ">
    <div class="topFiltrate">

      <p :class="dateType==1?'activep':''" @click="changedate(1)">调机报表 </p>
       <p :class="dateType==2?'activep':''" @click="changedate(2)">调机配置 </p>
      <p :class="dateType==3?'activep':''" @click="changedate(3)">机床参数 </p>

    </div>
    <div >
      <!-- 调机报表 -->
      <!-- <div class="bg "  style="width: 80%;margin: 20px auto" v-if="dateType==1">
        <a-table :columns="columns" :data-source="data" >
          <template slot="name" slot-scope="text, record">
            <img :src="record.name" alt="">
          </template>
        </a-table>
      </div> -->
      <div class="bg "  style="width: 80%;margin: 20px auto" v-if="dateType==1">
       <div style="width:100%">
         <table style="width:100%">
           <thead>
             <tr class="borderb" style="background-color: #e6e6e8;"><td > </td><td >项目 </td><td>调机值 </td></tr>
           </thead>
           <tbody>
            <tr class="borderb">
              <td><img :src="imgurl" alt="" ></td>
              <td>速度波动百分比[%] <span style="margin-left:20px">X</span> </td>
              <td v-if="machineResult.VS">{{ havedata(machineResult.VS.X)}} </td>
                <td v-else>/ </td>
            </tr>
            <tr class="borderb">
              <td><img :src="imgurl" alt="" ></td>
              <td>速度波动百分比[%] <span style="margin-left:20px">Y</span> </td>
               <td v-if="machineResult.VS">{{ havedata(machineResult.VS.Y)}} </td>
                 <td v-else>/ </td>
            </tr>
            <tr class="borderb">
              <td><img :src="imgurl" alt="" ></td>
              <td>速度波动百分比[%] <span style="margin-left:20px">Z</span> </td>
               <td v-if="machineResult.VS">{{ havedata(machineResult.VS.Z)}} </td>
                 <td v-else>/ </td>
            </tr>
            <tr class="borderb">
              <td><img :src="imgurl" alt="" ></td>
              <td>跟随误差[mm] <span style="margin-left:20px">X</span> </td>
             <td v-if="machineResult.FE">{{ havedata(machineResult.FE.X)}} </td>
              <td v-else>/ </td>
            </tr>
            <tr class="borderb">
              <td><img :src="imgurl" alt="" ></td>
              <td>跟随误差[mm] <span style="margin-left:20px">Y</span> </td>
             <td v-if="machineResult.FE">{{ havedata(machineResult.FE.Y)}} </td>
               <td v-else>/ </td>
            </tr>
            <tr class="borderb">
              <td><img :src="imgurl" alt="" ></td>
              <td>跟随误差[mm] <span style="margin-left:20px">Z</span> </td>
              <td v-if="machineResult.FE">{{ havedata(machineResult.FE.Z)}} </td>
                <td v-else>/ </td>
            </tr>
             <tr class="borderb">
              <td><img :src="imgurl" alt="" ></td>
              <td>圆度不匹配度[um]</td>
              <td>{{ havedata(machineResult.CM)}} </td>
            </tr>
            <tr class="borderb">
              <td><img :src="imgurl" alt="" ></td>
              <td>刚性攻丝同步误差[um]</td>
              <td>{{ havedata(machineResult.RT)}} </td>
            </tr>
            <tr class="borderb">
              <td><img :src="imgurl" alt="" ></td>
              <td>龙门同步轴位置误差[mm]</td>
              <td>{{ havedata(machineResult.PE)}} </td>
            </tr>
            <tr class="borderb">
              <td><img :src="imgurl" alt="" ></td>
              <td>龙门同步轴电流误差[A]</td>
              <td>{{ havedata(machineResult.CE)}} </td>
            </tr>
             <tr class="borderb">
              <td><img :src="imgurl" alt="" ></td>
              <td>主轴升速时间[s](500 rpm)</td>
              <td>{{ havedata(machineResult.TE)}} </td>
            </tr>
             <tr class="borderb">
              <td><img :src="imgurl" alt="" ></td>
              <td>主轴降速时间[s](500 rpm)</td>
              <td>{{ havedata(machineResult.TI)}} </td>
            </tr>
             <tr class="borderb">
              <td><img :src="imgurl" alt="" ></td>
              <td>换刀时间[s]15->10)</td>
              <td>{{havedata(machineResult.TC)}} </td>
            </tr>
            
           </tbody>
         </table>
          <!-- <a-empty v-if="havelsit==0" style="margin:50px 0;padding-bottom:50px"/> -->
       </div>
      </div>
      <!-- 调机配置 -->
      <div  style="width: 80%;margin: 20px auto" v-if="dateType==2">
        <div class="bg " style="width:100%;padding:20px;margin-bottom:20px">
             <div class="divbox">
               <div><h3>速度环</h3>
                <h4> <p class="divboxname"> 行程： </p> <p v-if="Config.speed"><span  v-if="Config.speed.X" >X：{{Config.speed.X.dis}}</span> <span  v-if="Config.speed.Y" >Y：{{Config.speed.Y.dis}}</span> <span  v-if="Config.speed.Z" >Z：{{Config.speed.Z.dis}}</span></p></h4>
               <h4> <p class="divboxname"> 速度：</p> <p v-if="Config.speed"><span  v-if="Config.speed.X" >X：{{Config.speed.X.spe}}</span> <span  v-if="Config.speed.Y" >Y：{{Config.speed.Y.spe}}</span> <span  v-if="Config.speed.Z" >Z：{{Config.speed.Z.spe}}</span></p></h4>
               <h4><p class="divboxname">采样周期：</p><p v-if="Config.speed"><span  v-if="Config.speed.X" >X：{{Config.speed.X.period}}</span> <span  v-if="Config.speed.Y" >Y：{{Config.speed.Y.period}}</span> <span  v-if="Config.speed.Z" >Y:{{Config.speed.Z.period}}</span></p></h4> </div>
               <div> <h3>位置环</h3>
               <h4><p class="divboxname">行程：</p><p v-if="Config.pos"><span  v-if="Config.pos.X" >X：{{Config.pos.X.dis}}</span> <span  v-if="Config.pos.Y" >Y：{{Config.pos.Y.dis}}</span> <span  v-if="Config.pos.Z" >Z：{{Config.pos.Z.dis}}</span></p></h4>
               <h4><p class="divboxname">速度：</p><p v-if="Config.pos"><span  v-if="Config.pos.X" >X：{{Config.pos.X.spe}}</span> <span  v-if="Config.pos.Y" >Y：{{Config.pos.Y.spe}}</span> <span  v-if="Config.pos.Z" >Z：{{Config.pos.Z.spe}}</span></p></h4>
               <h4><p class="divboxname">采样周期：</p><p v-if="Config.pos"><span  v-if="Config.pos.X" >X：{{Config.pos.X.period}}</span> <span  v-if="Config.pos.Y" >Y：{{Config.pos.Y.period}}</span> <span  v-if="Config.pos.Z" >Z：{{Config.pos.Z.period}}</span></p></h4> </div>
             </div>
        </div>
        <div class="bg " style="width:100%;padding:20px;margin-bottom:20px">
          <h3>圆度测试</h3>
             <div class="divbox">
               <div>
                 <h4> <p class="divboxname">是否绘制指令位置：</p>  <p v-if="Config.cir"> {{Config.cir.drawcmd}}</p></h4>
               <h4><p class="divboxname">纵轴轴号：</p>   <p v-if="Config.cir"> {{Config.cir.ax_h}}</p></h4>
               <h4><p class="divboxname">速度：</p>  <p v-if="Config.cir"> {{Config.cir.velocity}}</p></h4> 
               <h4><p class="divboxname">横轴轴号：</p>  <p v-if="Config.cir"> {{Config.cir.ax_v}}</p></h4></div>
               <div><h4><p class="divboxname">轨迹(0:正圆，1:逆圆)：</p>  <p v-if="Config.cir"> {{Config.cir.trace}}</p></h4>
               <h4><p class="divboxname">全闭环：</p>  <p v-if="Config.cir"> {{Config.cir.fullclosed}}</p></h4>
               <h4><p class="divboxname">半径：</p>  <p v-if="Config.cir"> {{Config.cir.radius}}</p></h4>
               <h4><p class="divboxname">采样周期：</p>  <p v-if="Config.cir"> {{Config.cir.preiod}}</p></h4> </div>
             </div>
        </div>
        <div class="bg " style="width:100%;padding:20px;margin-bottom:20px">
          <h3>刚性攻丝</h3>
             <div class="divbox">
               
               <div>
                  <h4> <p class="divboxname">平面：</p>  <p v-if="Config.tap"> {{Config.tap.plane}}</p></h4> 
                    <h4> <p class="divboxname">螺距：</p>  <p v-if="Config.tap"> {{Config.tap.thread_lead}}</p></h4> 
                    <h4> <p class="divboxname">主轴反向指令：</p>  <p v-if="Config.tap"> {{Config.tap.tapSpdlReverseM}}</p></h4> 
                      <h4> <p class="divboxname">攻丝深度：</p>  <p v-if="Config.tap"> {{Config.tap.drill_deep}}</p></h4> 
                        <h4> <p class="divboxname">攻丝指令：</p>  <p v-if="Config.tap"> {{Config.tap.type}}</p></h4> 
                          <h4> <p class="divboxname">攻丝旋转轴：</p>  <p v-if="Config.tap"> {{Config.tap.tapRotateAxis}}</p></h4> 
                            <h4> <p class="divboxname">主轴停止命令：</p>  <p v-if="Config.tap"> {{Config.tap.tapSpdlStopM}}</p></h4> 
               </div>
               <div>

                 <h4> <p class="divboxname">下移距离：</p>  <p v-if="Config.tap"> {{Config.tap.down_height}}</p></h4> 
                    <h4> <p class="divboxname">孔底停留时间：</p>  <p v-if="Config.tap"> {{Config.tap.pause_time}}</p></h4> 
                    <h4> <p class="divboxname">速度：</p>  <p v-if="Config.tap"> {{Config.tap.spe}}</p></h4> 
                      <h4> <p class="divboxname">攻丝旋转轴轴号：</p>  <p v-if="Config.tap"> {{Config.tap.sync_axis}}</p></h4> 
                        <h4> <p class="divboxname">攻丝进给轴轴号：</p>  <p v-if="Config.tap"> {{Config.tap.tap_axis}}</p></h4> 
                          <h4> <p class="divboxname">主轴正传命令：</p>  <p v-if="Config.tap"> {{Config.tap.tapSpdlForwardM}}</p></h4> 
               </div>
             </div>
        </div>
         <div class="bg " style="width:100%;padding:20px;margin-bottom:20px">
          <h3>龙门同步</h3>
             <div class="divbox">
               <div>
                  <h4> <p class="divboxname">重动轴轴号：</p>  <p v-if="Config.sync"> {{Config.sync.sync_axis2}}</p></h4> 
                    <h4> <p class="divboxname">引导轴轴号：</p>  <p v-if="Config.sync"> {{Config.sync.sync_axis1}}</p></h4> 
                   
                </div>
               <div>
                  <h4> <p class="divboxname">采样周期：</p>  <p v-if="Config.sync"> {{Config.sync.sync_period}}</p></h4> 
                  <h4> <p class="divboxname">速度：</p>  <p v-if="Config.sync"> {{Config.sync.axis_f}}</p></h4> 
                       
                </div>
             </div>
        </div>
        <div class="bg " style="width:100%;padding:20px;margin-bottom:20px">
          <h3>主轴升降速</h3>
             <div class="divbox">
               <div>
                   <h4> <p class="divboxname">主轴轴号：</p>  <p v-if="Config.spindle"> {{Config.spindle.axisNo}}</p></h4> 
                  <h4> <p class="divboxname">采样周期：</p>  <p v-if="Config.spindle"> {{Config.spindle.period}}</p></h4> 
                   <h4> <p class="divboxname">暂停时间：</p>  <p v-if="Config.spindle"> {{Config.spindle.pauseTime}}</p></h4> 
                    <h4> <p class="divboxname">主轴转速：</p>  <p v-if="Config.spindle"> {{Config.spindle.speed}}</p></h4> 
           
                  </div>
               <div>
                  <h4> <p class="divboxname">反转指令：</p>  <p v-if="Config.spindle"> {{Config.spindle.spdlReverseM}}</p></h4> 
                  <h4> <p class="divboxname">停止指令：</p>  <p v-if="Config.spindle"> {{Config.spindle.spdlStopM}}</p></h4> 
                   <h4> <p class="divboxname">主轴修调：</p>  <p v-if="Config.spindle"> {{Config.spindle.spdlRate}}</p></h4> 
                    <h4> <p class="divboxname">旋转指令：</p>  <p v-if="Config.spindle"> {{Config.spindle.spdlForwardM}}</p></h4> 
               </div>
             </div>
        </div>
        <div class="bg " style="width:100%;padding:20px;margin-bottom:20px">
          <h3>换刀时间</h3>
             <div class="divbox">
               <div>
                  <h4> <p class="divboxname">当前刀号：</p>  <p v-if="Config.tool"> {{Config.tool.curTool}}</p></h4> 
                   <h4> <p class="divboxname">寄存器：</p>  <p v-if="Config.tool"> {{Config.tool.toolReg}}</p></h4> 
                    <h4> <p class="divboxname">寄存器号：</p>  <p v-if="Config.tool"> {{Config.tool.toolIdx}}</p></h4> 
                     
                </div>
               <div>
                  <h4> <p class="divboxname">采样周期：</p>  <p v-if="Config.tool"> {{Config.tool.toolPeriod}}</p></h4> 
                   <h4> <p class="divboxname">换刀刀号：</p>  <p v-if="Config.tool"> {{Config.tool.toolNo}}</p></h4> 
                    <h4> <p class="divboxname">寄存器位：</p>  <p v-if="Config.tool"> {{Config.tool.toolBit}}</p></h4> 
                </div>
             </div>
        </div>
        
      </div>
       <!-- 机床参数 -->
      <div class="bg "  style="width: 80%;margin: 20px auto" v-if="dateType==3">
       <div style="width:100%">
         <table style="width:100%">
           <thead>
             <tr class="borderb" style="background-color: #e6e6e8;"><td > </td><td >参数号 </td><td>参数名 </td><td>参数值 </td></tr>
           </thead>
       
           <tbody v-for="(item,i) in parmList" :key="i">
                 <tr class="borderb" v-for="(el,index) in item.data" :key="index">
                   <td :rowspan="item.data.length"  v-if="index==0" >{{item.name}} </td>
                   <td class="borderl">{{el.param}} </td>
                   <td>{{el.name}} </td>
                   <td>{{el.value}} </td></tr>
           </tbody>
         </table>
          <a-empty v-if="havelsit==0" style="margin:50px 0;padding-bottom:50px"/>
       </div>
      </div>
    </div>
  </div>
</template>
<script>
//
const columns = [
  {
    title: "",
    dataIndex: "name",
    scopedSlots: { customRender: 'name' },
  },
  {
    title: "项目",
    dataIndex: "age",
      scopedSlots: { customRender: 'name' },
  },
  {
    title: "调机值",
    dataIndex: "address",
     scopedSlots: { customRender: 'name' },
  }
];

let colorList=['#FF3535','#FF7865','#FFBB00','#f8d77e']
import api from "@/api/deviceInfo.js";
export default {
  data() {
    return {
      data:[],
      columns,
      form: { num: 1 },
      options1: [{ name: "生产车间1", value: 1 }, { name: "生产车间2", value: 2 }],
      options2: [{ name: "2333", value: 1 }, { name: "3444", value: 2 }],
      colorList:colorList,
      dateType:1,
      params:{page:1,
        pageSize:10

      },
      machineReportData:{},
       machineResult:{},//报表
       Config:{},
       parmList:[],
       havelsit:0,
       imgurl:require('@images/gongshi1.png')
    };
  },
  created() {
    this.machineReportData= JSON.parse(localStorage.getItem('machineReportData')) 
    console.log(this.machineReportData)
    this.machineResult=this.machineReportData.result
    this.Config=this.machineReportData.Config
    // this.macsn=this.$route.query.macsn;
    let array = this.machineReportData.Parm.parm
			let list = []
      this.havelsit=0
			array.forEach(item => {
				if (item.param == '100000' || item.param == '101000' || item.param == '102000') {
					list.push({
						name: item.value + '轴参数',
						data: []
					})
				}
			})
			list.push({
				name: '通道参数',
				data: []
			})
			for(var i = 0; i < array.length; i ++){
				let item = array[i]
				if (item.param == '100000' || item.param == '101000' || item.param == '102000') {
					continue;
				}
				let str = item.param.substring(0, 3)
				if (str == '100') {
					let obj = list.find(e => e.name == 'X轴参数')
					obj.data.push(item)
				} else if (str == '101') {
					let obj = list.find(e => e.name == 'Y轴参数')
					obj.data.push(item)
				} else if (str == '103') {
					let obj = list.find(e => e.name == 'Z轴参数')
					obj.data.push(item)
				} else if (str == '040') {
					let obj = list.find(e => e.name == '通道参数')
					obj.data.push(item)
				}
			}
			this.parmList = list
      if(list.length>0){
        list.forEach(item=>{
          if(item&&item.data.length>0){
                this.havelsit++
          }
        })
      }
      // console.log(	this.havelsit)

      // console.log(	this.parmList)
  },
  methods: {
      havedata(data){
     
      let str=""
        if(data==0){
            str=0
        }else if(data==null||data==undefined||data==""){
         
           str="/"
        }else{
            str=data
        }
     
          return str
    },
    changedate(index){
      this.dateType=index
    },
  }
};
</script>
<style scoped lang="less">
@import "./index.less";
.borderl{
  border-left: 1px solid #e6e6e8;
}
.borderb{
  border-bottom: 1px solid #e6e6e8;

}
td{
  font-size: 15px;
  line-height: 32px;
  padding:10px 10px;
  text-align: center;
  img{
    height: 40px;
    width: auto;
  }
  
}
</style>
